package com.zhenwei.zscm.service;

import com.zhenwei.zscm.common.base.RestResult;
import com.zhenwei.zscm.model.vo.menu.MenuVO;
import com.zhenwei.zscm.repo.LogRepo;
import com.zhenwei.zscm.repo.MenuRepo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class MenuService {
    private MenuRepo menuRepo;
    private LogRepo logRepo;

    public RestResult all(){
        var list = menuRepo.all();
        return RestResult.success(list, list.size());
    }

    public RestResult create(MenuVO vo){
        boolean b = menuRepo.create(vo);
        if(b) {
            String LOG_TYPE = "菜单管理";
            logRepo.createAsync(LOG_TYPE, "新建菜单->"+vo);
        }
        return RestResult.r(b);
    }
}
